#ifndef PTM_H
#define PTM_H

#include <QTime>
#include <QFileInfo>
#include <QtXml/QXmlDefaultHandler>
#include <QDomDocument>
#include <QTableWidget>
#include <QApplication>

class PTMWidget : virtual public QTableWidget {
public:
    PTMWidget (QWidget * parent = 0);
    virtual ~PTMWidget (void);

    bool loadFromXML (const QString& filePath = qApp->applicationDirPath () + "/presentation/_ptm.xml");
    bool saveToXML (const QString& filePath = qApp->applicationDirPath () + "/presentation/_ptm.xml");
    const QString& getName (void) const;
    bool setName(const QString& name);
    bool setBaseTime (const QTime& baseTime);
    bool baseTimeToCurrentTime (unsigned int row = 0);
    const QTime& getBaseTime (void) const;
    void incEventDuration (const unsigned int row, const unsigned int minutes = 5);
    bool setDisabledRows (const unsigned int startRow, const unsigned int endRow);
    bool setEnabledRows (const unsigned int startRow, const unsigned int endRow);
    virtual void clear (void);
private:
    class XMLReader : public QXmlDefaultHandler {
    public:
        XMLReader (PTMWidget* ptmWidget, const QString& filePath);

        virtual bool startElement (const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& attribs);
        virtual bool characters (const QString& str);
        bool isRead (void) const;
    private:
        bool elementEvent (const QString& type, const int duration, const QString& title, const QString& author, const QString& link);

        PTMWidget* ptmWidget;
        QString currentText;
        int presentationCount;
        int eventDuration;
        QString xmlDirectory;
        bool readResult;
    };
    class XMLWriter {
    public:
        XMLWriter (PTMWidget* ptmWidget, const QString& filePath, const QString& codec = "UTF-8");
        bool isWrite (void) const;
    private:
        bool writeResult;
    };

    QString name;
    QTime baseTime;
};

#endif // PTM_H
